/**
 * @author QL
 * @date 2021-12-24 11:23:27
 * @version V..
 * @description 全局变量配置文件
 * 1. ip:host / 域名端口配置参数
 * 2. 开发/生产等环境配置参数
 * 3. 其余自定义全局配置参数
 */

 import UtilMethods from './UtilMethods.js'

class GlobalVariable {
	constructor() {
		this.utils = new UtilMethods();

		/**
		 * @author QL
		 * @param {Array}  serviceAlias 一个自定义服务别名的列表
		 * @param {String} XXX_IP    XXX为自定义的服务别名
		 * @param {String} XXX_HOST  XXX为自定义的服务别名
		 * @date 2021-12-24 11:25:28
		 * @version V..
		 * @description ip/域名 端口配置部分
		 */
		this.serviceAlias = ['default', 'login', 'webSocket'];

		this.default_IP = ""
		this.default_HOST = ""

		this.login_IP = ""
		this.login_HOST = ""

		this.webSocket_IP = ""
		this.webSocket_HOST = ""


		this.token = "tokenTest"

		/**
		 * @author QL
		 * @param {String}   developMode ['develop','production']
		 * @date 2021-12-24 11:26:01
		 * @version V..
		 * @description 开发/生产环境ip端口配置部分
		 */
		this.developMode = process.env.NODE_ENV

		/**
		 * 其余全局配置变量
		 * @param {String} JEpublicKey  加密算法公钥
		 */
		this.JEpublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpsfRSFf22HSHeoooXzfdEIDCzLPBq3t+TvcsI/vQ/DoLgpdqGilN5z+YRmchayNKPVUVJYpb4zZQjFLxNfICe6G7tjOlLufrITSMaOXweOQc+UTJ8DFteFhbKT/iwj/aYNgDG/XPbxUB4kJYWcUbniOr5wh55/3Gtnz6k1niAgwIDAQAB'

		/**
		 * @author QL
		 * @date 2021-12-24 11:26:47
		 * @description 构造器逻辑方法部分
		 */
		if (this.developMode) {
			// this.utils.setConsole("启动的模式：", process.env.NODE_ENV)
			switch (this.developMode) {
				case "dev":
					this.default_IP = "http://10.10.29.184"
					this.default_HOST = ":8091"

					this.login_IP = "http://10.10.29.184"
					this.login_HOST = ":14102"

					this.webSocket_IP = "ws://10.10.29.184"
					this.webSocket_HOST = ":8093"

					this.fileUpload_IP = "http://10.10.29.184"
					this.fileUpload_HOST = ":8092"
					break
				case "prod":
					this.default_IP = "http://wx.gisocn.com"
					this.default_HOST = ":19091"

					this.login_IP = "http://wx.gisocn.com"
					this.login_HOST = ":19002"

					this.webSocket_IP = "ws://wx.gisocn.com"
					this.webSocket_HOST = ":19093"
					break
				default:
					break
			}
		}
	}
	/**
	 * @author QL
	 * @date 2021-12-24 11:45:10
	 * @version V..
	 * @description  _get _set 方法部分
	 */
	_getIPHOST(serverName) {
		try {
			if (this.serviceAlias.indexOf(serverName) != -1) {
				return this[serverName + "_IP"] + this[serverName + "_HOST"];
			} else {
				throw new Error("未定义的服务别名, 将使用default服务ip端口")
			}
		} catch (e) {
			this.utils.setConsole("服务别名异常：" + "(" + serverName + ")", e);
			//TODO handle the exception
			return this.default_IP + this.default_HOST;
		}
	}

	_getToken() {
		return this.token;
	}

	_setIP(serverName, val) {
		this[serverName + "_IP"] = val;
	}
	_setHOST(serverName, val) {
		this[serverName + "_HOST"] = val;
	}

}

export default GlobalVariable
